/*
 *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.base.feign.interceptor;

import com.iwindplus.base.feign.domain.property.FeignProperty;
import com.iwindplus.base.util.HttpsUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import jakarta.annotation.Resource;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;

/**
 * Feign请求过滤器.
 *
 * @author zengdegui
 * @since 2020/4/23
 */
@Slf4j
public class FeignRequestInterceptor implements RequestInterceptor {

    @Resource
    private FeignProperty property;

    @Override
    public void apply(RequestTemplate template) {
        if (Boolean.FALSE.equals(this.property.getRequest().getEnabled())) {
            return;
        }

        Optional.ofNullable(HttpsUtil.getMdc()).ifPresent(mdc -> mdc.forEach(template::header));
    }
}
